var dxrz = {
    alwayShowDetail:function (rowData) {
        $('#layout_dxrz').layout('remove', 'center');
        $('#layout_dxrz').layout('add', {
            region:'center',
            split:true,
            href:$.webPath() + '/base/dxrz/dxrz_detail?dxrzId=' + rowData.id
        });
    },
    showDetail:function (rowData) {
        if ($("#dxrz_detail_id").val() != rowData.id) {
            dxrz.alwayShowDetail(rowData);
        }
    }
}
$(function () {
    //表格初始加载
    $('#grid_dxrz').datagrid({
        url: $.webPath() + "/base/dxrz/dxrzList",
        toolbar: "#toolbar_dxrz",
        fitColumns: true,
        pageNumber: 1,
        singleSelect: true,
        pagination: true,
        fit: true,
        rownumbers: true,
        striped: true,
        columns: [
            [
                {field: 'fsrXms', title: '发送人', width: 20},
                {field: 'fsrq_time', title: '发送日期', width: 15},
                {field: 'content', title: '内容', width: 70},
                {field: 'sffscg', title: '发送状态', width: 15,formatter:function(v){
                    if(v == '是') {return "发送成功";} else {return "发送失败";}
                }},
                {field: 'errormessage', title: '失败原因', width: 15}
            ]
        ],
        onLoadSuccess: function () {
            $(this).datagrid('selectRow', 0);
        },
        onSelect:function (rowIndex, rowData) {
            if(rowData!=null){
                dxrz.showDetail(rowData);
            }
        }
    });

    //查询按钮
    $("#btn_dxrz_search").click(function () {
        dxrz_search();
    });
    $("#btn_dxrz_test").click(function(){
        dxrz_test('短信测试', 'test_dxrz');
    });
});

//查询短信配置
function dxrz_search() {
    $('#grid_dxrz').datagrid('load',
        {
            fsrq:$('#dxrz_fsrq').datebox('getValue')
        }
    );
}

//修改短信配置
function dxrz_test(title, action) {
    var href = $.webPath() + "/base/dxrz/dxrz_content";
    var actionUrl = $.webPath() + "/base/dxrz/dxrz_test";
    dxrz_showDialog(title, href, actionUrl);
}



//弹框调用方法
function dxrz_showDialog(title, href, actionUrl) {
    var win = $.window({
        title:title,
        iconCls:'icon-add2',
        width:500,
        height:300,
        cache:false,
        url:href,
        modal:true,
        buttons:[
            {
                text:'测试',
                handler:function () {
                    $(win).mask();
                    $('#form_dxrz').form('submit', {
                        url:actionUrl,
                        onSubmit:function (param) {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $(win).mask('hide');
                                return false;
                            }
                            return isValid;
                        },
                        success:function (data) {
                            $(win).mask('hide');
                            var json = $.parseJSON(data);
                            if (json.statusCode == 200) {
                                $(win).window('close');
                                $("#grid_dxrz").datagrid('reload');
                                $.messager.show({
                                    title:'提示',
                                    msg:json.message,
                                    timeout:3000,
                                    showType:'slide'
                                });
                            } else
                                $.messager.alert('提示', json.message, 'error');
                        }
                    });
                }
            }
        ]
    });
}